package com.tellhow.monitorserverqh.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.tellhow.monitorserverqh.mapper.SmsMapper;
import com.tellhow.monitorserverqh.model.SmsModel;
import com.tellhow.monitorserverqh.service.ISms;
import javafx.scene.chart.ScatterChart;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:gnplum
 * @Date: 2023/5/6  10:51
 * @Version 1.0
 */
@Data
@Service
public class SmsImpl implements ISms {
    private static final Log logger = LogFactory.getLog(SmsImpl.class);
    @Resource
    SmsMapper smsMapper;
    //分组短信ID
    @Value("${sms.info.groupid}")
    private String groupid;

    @Override
    public void sendSMS() {
        //List<SmsModel> smsModelList = new ArrayList<>();
        try {
            List<SmsModel> list = smsMapper.querySendSmsInfos(groupid);
            logger.info(">> list=" + list);
            String strSmsid = "";
            if (CollectionUtils.isNotEmpty(list)) {
                for (SmsModel smsModel : list) {
                    strSmsid = smsModel.getSms_id();
                    if (!StringUtils.isBlank(strSmsid)) {
                        //当天是否已插入短信表
                        int strIsSend = smsMapper.searchIsSendSms(strSmsid);
                        if (strIsSend == 0) {
                            //插入短信表
                            smsMapper.insertSms(list);
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error(">> 监控异常内容插入异常：" + e.getStackTrace() + e.getMessage());
            e.printStackTrace();
        }
    }
}
